package hl.leco.colle;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * 
 * @author Liu Huan
 */


public class CollectionStuTest {
	public static void main(String[] args) {
		// 创建对象
		Collection collection = new ArrayList();
		Student stu1 = new Student("张三",15);
		Student stu2 = new Student("李四",16);
		Student stu3 = new Student("王五", 20);
		// 增
		collection.add(stu1);
		collection.add(stu2);
		collection.add(stu3);
		System.out.println("集合大小：" + collection.size());
		System.out.println("集合是否为空："+collection.isEmpty());
		System.out.println("集合是否有 张三 ：" + collection.contains(stu1));
		// 对象是单独存储的，集合中存储的只是对象的引用
		System.out.println("集合是否有 张三 15：" + collection.contains(new Student("张三",15)));
		
		// 删
		collection.remove(stu2);
		System.out.println("集合大小：" + collection.size());
		
		// 遍历
		for (Object o : collection) {
			System.out.println(o.toString());
		}
		
		Iterator iterator = collection.iterator();
		while (iterator.hasNext()){
			System.out.println(iterator.next());
		}
		
	}
}
